/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import static persistencia.DBManagerPacientes.conexion;
import modelo.Pacientes;
import modelo.MetodosPacientes;


/**
 * aprobecharemos el codigo de Creacion y añadiremos de esta un combo box 
 * para elegir el modelo antiguo que le pasaremos al update como campo where
 * @author Kevin
 */
public class JPModificarPaciente extends javax.swing.JPanel {

 
    ArrayList<Pacientes> al;
   
    
    
  public void RellenarComboPaciente() throws SQLException, ClassNotFoundException{
       
        jCombo_CodPaciente.removeAllItems();
        MetodosPacientes mtp= new MetodosPacientes();
        al = mtp.getIPacientes();
        for (int i = 0; i < al.size(); i++) {
            jCombo_CodPaciente.addItem(al.get(i).getNombre()); //+al.get(i).getNombre());
        }
    }

    public JPModificarPaciente() throws SQLException, ClassNotFoundException {
        initComponents();
        
            jbModificar.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               
                int codPaciente = (int) jCombo_CodPaciente.getSelectedItem();
                    Pacientes cPaciente = new Pacientes(Integer.toString(codPaciente));
                String codPacienteNuevo = jTextFieldCodPacienteNuevo.getText();
                    Pacientes cnPacientes = new Pacientes(codPacienteNuevo);
                String dniPaciente = jTextFieldDniNuevo.getText();
                    Pacientes dnPacientes = new Pacientes(dniPaciente);
                String PrimerApellidoPaciente = jTextField_ApellidoNuevo.getText();
                    Pacientes pApellidoPacientes = new Pacientes(PrimerApellidoPaciente);
                    
                    MetodosPacientes mtp = null;
                try {
                    mtp = new MetodosPacientes();
                    mtp.modPaciente(cPaciente,cnPacientes, dnPacientes, pApellidoPacientes);
                    System.out.println ("PACIENTE MODIFICADO");
                        RellenarComboPaciente();
                } catch (ClassNotFoundException ex){
                    System.err.println ("DRIVER NO ENCONTRADO.");
                    ex.printStackTrace();
                } catch (SQLException ex) {
                    System.err.println ("SQLEXCEPTION.");
                    ex.printStackTrace();
                }
               }
        });
        
    }
   

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbModificar = new javax.swing.JButton();
        jLabelPacienteNuevo = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        labelPacienteAntiguo = new javax.swing.JLabel();
        jLabelDniNuevo = new javax.swing.JLabel();
        jLabelApellido = new javax.swing.JLabel();
        jTextFieldCodPacienteNuevo = new javax.swing.JTextField();
        jTextFieldDniNuevo = new javax.swing.JTextField();
        jTextField_ApellidoNuevo = new javax.swing.JTextField();
        jCombo_CodPaciente = new javax.swing.JComboBox();

        jbModificar.setText("Modificar");

        jLabelPacienteNuevo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabelPacienteNuevo.setText("CodPaciente nuevo:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel3.setText("Modificar Paciente");

        labelPacienteAntiguo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        labelPacienteAntiguo.setText("CodPaciente Antinguo:");

        jLabelDniNuevo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabelDniNuevo.setText("DNI Nuevo:");

        jLabelApellido.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabelApellido.setText("Primer Apellido nuevo:");

        jTextFieldCodPacienteNuevo.setText("jTextField2");

        jTextFieldDniNuevo.setText("jTextField3");

        jTextField_ApellidoNuevo.setText("jTextField4");

        jCombo_CodPaciente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(126, 126, 126))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabelDniNuevo)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jTextFieldDniNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabelApellido)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField_ApellidoNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(labelPacienteAntiguo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jCombo_CodPaciente, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(18, 18, 18)
                        .addComponent(jLabelPacienteNuevo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFieldCodPacienteNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(188, 188, 188)
                        .addComponent(jLabel3)))
                .addContainerGap(33, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabelPacienteNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextFieldCodPacienteNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(labelPacienteAntiguo, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jCombo_CodPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelDniNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldDniNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField_ApellidoNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(4, 4, 4)
                .addComponent(jbModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jCombo_CodPaciente;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelApellido;
    private javax.swing.JLabel jLabelDniNuevo;
    private javax.swing.JLabel jLabelPacienteNuevo;
    private javax.swing.JTextField jTextFieldCodPacienteNuevo;
    private javax.swing.JTextField jTextFieldDniNuevo;
    private javax.swing.JTextField jTextField_ApellidoNuevo;
    private javax.swing.JButton jbModificar;
    private javax.swing.JLabel labelPacienteAntiguo;
    // End of variables declaration//GEN-END:variables
}
